package my.jieh.tips.swing.order;

import java.awt.*;
import javax.swing.*;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */

 public class AlphaPolicy {
   public static void main(String args[]) {
     String labels[] = {"Henry VII", "Henry VIII",
       "Edward VI", "Jane", "Mary I", "Elizabeth I"};
     JFrame frame = new JFrame();
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     Container content = frame.getContentPane();
     JPanel panel = new JPanel();

     panel.setFocusTraversalPolicy(new AlphaOrderFocusTraversalPolicy());
     panel.setFocusCycleRoot(true);
     for (int i=0, n=labels.length; i<n; i++) {
       JButton button = new JButton(labels[i]);
       panel.add(button);
     }
     content.add(panel, BorderLayout.CENTER);
     frame.pack();
     frame.show();
     panel.getComponent(0).requestFocusInWindow();
   }
 }
